﻿using System;
using Drill.Extensibility;
using Drill.DrillBits.StructureMap.TestHelpers;
using Drill.TestSupport;
using Drill.TestSupport.TestDomains.AutomobileDomain;
using NUnit.Framework;

namespace Drill.DrillBits.StructureMap
{
	[TestFixture]
	public class StructureMapDrillBitConfigProviderTests
	{
		[Category("UnitTest")]
		[Test]
		public void CanConfigure()
		{
			// Arrange
			IDrillBitInitContext initializationContext =
				StructureMapTestConfigs.CreateStructureMapProviderInitializationContext();
			IDrillBit drillBit = new StructureMapDrillBit(initializationContext);
			StructureMapDrillBitSetupTestClass drillBitSetup = new StructureMapDrillBitSetupTestClass();

			// Act
			// ReSharper disable ExpressionIsAlwaysNull
			drillBitSetup.Configure(drillBit, null);
			IVehicle vehicle = drillBit.GetInstance<IVehicle>();
			// ReSharper restore ExpressionIsAlwaysNull

			// Assert
			Assert.That(vehicle, Is.Not.Null);
			Assert.That(vehicle, Is.TypeOf(typeof(Car)));
		}

		[Category("UnitTest")]
		[ExpectedException(typeof(ArgumentNullException), ExpectedMessage = "drillBit", MatchType = MessageMatch.Contains)]
		[Test]
		public void CannotConfigureWithNullDrillBit()
		{
			// Arrange
			StructureMapDrillBitSetupTestClass drillBitSetup = new StructureMapDrillBitSetupTestClass();
			IDrillBit drillBit = null;

			// Act
			// ReSharper disable ExpressionIsAlwaysNull
			drillBitSetup.Configure(drillBit, null);
			// ReSharper restore ExpressionIsAlwaysNull

			// Assert
			// Nothing to assert because the test should throw an expected exception (see ExpectedException attribute).
		}

		[Category("UnitTest")]
		[ExpectedException(typeof(ArgumentException), ExpectedMessage = "The drillBit parameter must be an instance of", MatchType = MessageMatch.Contains)]
		[Test]
		public void CannotConfigureWithIvalidDrillBitType()
		{
			// Arrange
			StructureMapDrillBitSetupTestClass drillBitSetup = new StructureMapDrillBitSetupTestClass();
			IDrillBit drillBit = new InvalidDrillBit();

			// Act
			// ReSharper disable ExpressionIsAlwaysNull
			drillBitSetup.Configure(drillBit, null);
			// ReSharper restore ExpressionIsAlwaysNull

			// Assert
			// Nothing to assert because the test should throw an expected exception (see ExpectedException attribute).
		}
	}
}